const merge = require('webpack-merge')
const wepackProdConfig = require('./webpack.base.config.js')
const WebpackBundleSizeAnalyzerPlugin = require('webpack-bundle-size-analyzer').WebpackBundleSizeAnalyzerPlugin
const path = require('path')
const config = require('./config.js')
const app = config.persional?config.wx.appname:config.wx.wmpname+'_'+config.wx.appname
const webpack = require('webpack')
module.exports = merge(wepackProdConfig, {
    output: {
        filename: '[hash].[name].js',
        path: path.resolve(__dirname, 'dist', app),
        publicPath: './',
        chunkFilename: '[chunkhash].js'
    },
    plugins: [
        new webpack.BannerPlugin('版权所有，翻版必究'),
        new webpack.optimize.UglifyJsPlugin({
            output: {
                comments: false,
            },
            compress: {
                warnings: false
            }
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor',
            'minChunks': function (module, count) {
                // any required modules inside node_modules are extracted to vendor
                return (
                    module.resource &&
                    /\.js$/.test(module.resource) &&
                    module.resource.indexOf(
                        path.join(__dirname, '../node_modules')
                    ) === 0
                )
            }
        }),
        // extract webpack runtime and module manifest to its own file in order to
        // prevent vendor hash from being updated whenever app bundle is updated
        new webpack.optimize.CommonsChunkPlugin({
            name: 'manifest',
            chunks: ['vendor']
        }),
        new WebpackBundleSizeAnalyzerPlugin('./plain-report.txt')
    ]
})